package com.yuanrui.wechat.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 订阅消息处理器
 */
@Slf4j
@Component
public class SubscribeMsgHandler implements WechatMsgHandler {
    @Override
    public WechatMsgTypeEnum getMsgType() {
        return WechatMsgTypeEnum.SUBSCRIBE;
    }

    @Override
    public String dealMsg(Map<String, String> messageMap) {
        log.info("接收到的订阅消息为");
        String replyContent = "欢迎关注";
        String fromUserName = messageMap.get("FromUserName");
        String toUserName = messageMap.get("ToUserName");
        return "<xml>\n" +
                "  <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA[" + replyContent + "]]></Content>\n" +
                "</xml>";
    }
}
